#include <stdlib.h>
#include <stdio.h>

#include "general.h"
#include "sudoku.h"
#include "solver.h"
#include "dlx.h"

void gridSeedSparseMatrix (Grid g, SparseMatrix sm)
{
  int x, y, i;
  int sm_row;
  cell cur;
  int mask;

  for (y = 0; y < GRID_SIZE; y++)
    {
      for (x = 0; x < GRID_SIZE; x++)
	{
	  cur = gridIndex(g, x, y);
	  mask = 0x1;
	  for (i = 0; i < GRID_SIZE; i++)
	    {
	      if ((cur & mask) == 0)
		{
		  sm_row = candidateToRow(i+1, x, y);
		  removeRow(sm, sm_row);
		}
	      mask = mask << 1;
	    }
	}
    }
}

int main (int argc, char * argv[])
{
  char input[GRID_SIZE * GRID_SIZE + 1] = //"12344321........";
    "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......";

  Grid grid = newGrid();
  SparseMatrix sm = newSparseMatrix();
  
  popGrid(input, grid);
  printf("puzzle\n");
  prtGrid(grid, 1);
  printf("a1:\n");
  if (a1(grid))
    {
      printf("solved\n");
    }
  else
    {
      printf("not solved\n");
    }

  prtGrid(grid, 1);

  //prtSparseMatrix(sm);
  gridSeedSparseMatrix (grid, sm);
  //prtSparseMatrix(sm);

  printf("dlx:\n");
  dlx(sm);

  delSparseMatrix(sm);
  delGrid(grid);
  return 0;  

}

